// controller
// lines
#include "controller.h"
#include <stdio.h>
#include "glotech_headers.h"
#include "model.h"
#include "view.h"
#include <math.h>


struct controller {
	MODEL * m;
	VIEW * v;
};

typedef struct controller CONTROLLER;

CONTROLLER * init_controller(void){
	CONTROLLER * c;

	c = (CONTROLLER * ) malloc(sizeof(CONTROLLER));
	if(c == NULL){
		//ERROR_CODE = 10;
		return NULL;
	}
	c->m = init_model();
	c->v = init_view(PROBE);

	if(c->m == NULL){
		
		return NULL;
	}
	if(c->v == NULL){
		
		return NULL;
	}

	return c;

}

NODE * cont_read_driver(void){
	NODE * n;
	n = model_get_data();
	return n;
}





int cont_init_probe(void){
	// 1 -> model_init_probe()
	while(1){
		// update_probe_position()
	}
	return SUCCESS;
}

int cont_init_clock(void){
	return 0;
}

unsigned int calculate_delay(float multiplier){
	float x;
	x = pow(SAMPLE_RATE,-1);
	x *= multiplier;
	x *= 1000;
	return x;
	//return (unsigned int) floor(((1/SAMPLE_RATE) * multiplier)*1000);
}